using System;
using System.Collections;
using System.Collections.Generic;
using BehaviorDesigner.Runtime.Tasks;
using Unity.VisualScripting;
using UnityEngine;

public class Find : MonoBehaviour
{
    public bool find;
    public float shootTime;
    [HideInInspector] public float waitShotTime;
    [HideInInspector]public Vector3 targetPos;
    public bool haveTarget;
    
    [HideInInspector] public bool findLight;
    [HideInInspector] public GameObject curLight;
    private PlayerController player => FindObjectOfType<PlayerController>();

    private void Start()
    {
        waitShotTime = shootTime;
    }

    private void OnTriggerStay2D(Collider2D other)
    {
        if (other.CompareTag("Player") && !player.isSoldierHide)
        {
            find = true;
            haveTarget = true;
        }
        else if (other.CompareTag("NoLight"))
        {
            findLight = true;
            curLight = other.gameObject;
        }

        if (player.isSoldierHide)
        {
            find = false;
            targetPos = other.transform.position;
            waitShotTime = shootTime;
        }
    }

    private void OnTriggerExit2D(Collider2D other)
    {
        if (other.CompareTag("Player"))
        {
            find = false;
            targetPos = other.transform.position;
            waitShotTime = shootTime;
        }
    }
}
